var fs = require("fs")

// Thunk 化
// 改造成仅接收 callback 作为参数的函数
function readFile(path) {
  return function(callback) {
    fs.readFile(path, callback)
  }
}

function co(fn) {
  var gen = fn()

  function next(err, data) {
    var result = gen.next(data)
    if(!result.done) {
      result.value(next)
    }
  }

  next()
}

co(function*() {
  var data1 = yield readFile('./co.js')
  console.log(data1)
  var data2 = yield readFile('./gen.js')
  console.log(data2);
})

